<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2016/9/20
  Time: 15:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <jsp:include page="../../head.jsp"/>
    <title>已受理页面</title>
    <script type="application/javascript" src="../../js/gtimp3/declaration.js"></script>
    <script type="text/javascript">
        var formSetting = {
            title: "查询信息",
            module: 'query',
            columns: [
                {
                    name: "declaration_type",
                    label: "进出口类型",
                    type: "dropdown",
                    data: [["进口", "I"], ["出口", "E"]],
                    op: "eq",
                    minLength: 0
                }, {
                    name: "contract_no",
                    label: "合同协议号"
                }, {
                    name: "business_Id",
                    label: "业务编号"
                }, {
                    name: "container_no",
                    label: "集装箱号"
                },
                {
                    name: "data_type",
                    label: "直/转类型"
                },
                {
                    name: "company_co",
                    label: "收发货人",
                    type: "dropdown",
                    dropdownType: "ajax",
                    url: "../order-dropdown/company",
                    op: "eq",
                    minLength: 0,
                    keyWordName: "key",
                    success: function (data) {
                        data = data.results;
                        var array = new Array();
                        $.each(data, function (i, n) {
                            array.push([n["text"], n["value"]]);
                        });
                        return array;
                    }
                }, {
                    name: "bl_no",
                    label: "提运单号"
                }, {
                    name: "sno",
                    label: "报关单号"
                }, {
                    name: "confirm_Time",
                    label: "提交时间起",
                    type: "date",
                    op: "ge"
                }, {
                    name: "confirm_Time",
                    label: "提交时间止",
                    type: "date",
                    op: "le"
                }, {
                    name: "validate_Time",
                    label: "审核时间起",
                    type: "date",
                    op: "ge"
                }, {
                    name: "validate_Time",
                    label: "审核时间止",
                    type: "date",
                    op: "le"
                }, {
                    name: "work_No",
                    label: "三联单编号",
                    hidden: !${isFG}
                }, {
                    name: "customer.COM_NAME",
                    label: "实际托运人"
                }, {
                    name: "ACCEPTED_RESULT",
                    label: "申请驳回",
                    type: "dropdown",
                    data: [["是", "appliedReject"], ["否", "notApplyReject"]],
                    op: "eq",
                }, {
                    name: "is_tongguan_yth",
                    label: "通关一体化",
                    type: "dropdown",
                    data: [["是", "1"], ["否", "0"]],
                    op: "eq",
                    minLength: 0
                }
                <c:if test="${isSignWS eq true}">, {
                    name: "CONFIRM_TYPE",
                    label: "三联单确认",
                    type: "dropdown",
                    data: [["已确认", "1"], ["未确认", "0"]],
                    op: "eq",
                    minLength: 0
                }</c:if>],
            buttons: {
                custom: [{
                    id: "getShipInfoBtn",
                    value: "获取驳船数据",
                    click: function () {
                        var selectIds = $("#declarationsDataGrid").getGridParam("selarrrow");
                        if (!selectIds) {
                            jw.alert("请选择需要操作的记录！");
                        }
                        var ids = "";
                        for (var i = 0; i < selectIds.length; i++) {
                            ids += "," + selectIds[i];
                        }
                        $.ajax({
                                   url: "getShipInfos",
                                   type: "post",
                                   data: {"ids": ids},
                                   dataType: "json",
                                   cache: false,
                                   success: function (data) {
                                       if (data.result) {
                                           document.getElementById("queryButton").click();
                                           jw.alert(data.msg);
                                       } else {
                                           jw.alert(data.msg)
                                       }
                                   }
                               });
                    }
                }, {
                    id: "id3",
                    value: "一键放行",
                    click: function () {
                        var id = $("#declarationsDataGrid").jqGrid("getGridParam", "selrow");
                        if (id) {
                            doDeclarationOk(id, '一键放行');
                        } else {
                            alert("请选择需要操作的记录！");
                        }
                    }
                }, {
                    id: "syncQPDataBtn",
                    value: "同步QP小工具数据",
                    click: function () {
                        var selectedRowId = $("#declarationsDataGrid").jqGrid("getGridParam",
                                                                              "selarrrow");
                        try {
                            var sbids = selectedRowId.map(function (rowid) {
                                return $("#declarationsDataGrid").getRowData(rowid).businessId;
                            });
                        } catch (ex) {
                        }
                        syncQPData(selectedRowId, sbids);
                    }
                }, {
                    id: "updateTynoBtn",
                    value: "修改统一编号",
                    click: function () {
                        var selectedRowId = $("#declarationsDataGrid")
                            .getGridParam("selrow");
                        if (selectedRowId) {
                            var ntyno = prompt("请输入新的统一编号:");
                            if (ntyno) {
                                jw.alert("统一编号同步中,");
                                $(".bd")[0].parentElement.parentElement.parentElement.style.width =
                                    '450px';
                                $(".bd")[0].style.width = '400px';
                                $.ajax({
                                           type: "post",
                                           cache: false,
                                           url: "declaration-doUpdateQptyno",
                                           data: {"id": selectedRowId, "qptyno": ntyno},
                                           dataType: "json",
                                           success: function (result) {
                                               var rmsg = result.msg;
                                               $(".bd").each(function (i, dom) {
                                                   if ($(dom).text().indexOf("同步中") != -1) {
                                                       set = true;
                                                       $(dom).append(rmsg + "。<br/>");
                                                   }
                                               });
                                               syncQPData(selectedRowId,
                                                          $("#declarationsDataGrid").getRowData(
                                                              selectedRowId).businessId,
                                                          true);
                                           }
                                       });
                            }
                        } else {
                            jw.alert("请点击需要操作的数据!");
                        }
                    }
                }, {
                    id: "backBtn",
                    value: "返回",
                    click: function () {
                        history.go(-1);
                    }
                }, {
                    id: "rejectHandleBtn",
                    value: "处理驳回申请",
                    click: function () {
                        var ids = $('#declarationsDataGrid')
                            .jqGrid('getGridParam', 'selarrrow');
                        if (ids.length != 1) {
                            jw.alert("一次只能处理一份报关单");
                            return;
                        }
                        var rowData = $("#declarationsDataGrid").jqGrid('getRowData', ids[0]);
                        if (!rowData.applied) {
                            jw.alert("请选择已申请驳回的报关单");
                            return;
                        }
                        var declaId = rowData.id;
                        var url = "/business/reject/supplier/page?declaId=" + declaId;
                        layer.open({
                                       title: false,
                                       type: 2,
                                       content: url,
                                       area: ['500px', '230px'],
                                       end: function () {
                                           document.getElementById("chargebackBtn").parentNode
                                               .firstChild.click();
                                       }
                                   });
                    }
                }, {
                    id: "chargebackBtn",
                    value: "退单",
                    click: function () {
                        var ids = $('#declarationsDataGrid')
                            .jqGrid('getGridParam', 'selarrrow');
                        if (ids.length != 1) {
                            jw.alert("一次只能处理一份报关单");
                            return;
                        }
                        var rowData = $("#declarationsDataGrid").jqGrid('getRowData', ids[0]);
                        var declaId = rowData.id;
                        var url = "/business/reject/supplier/chargeBackPage?declaId=" + declaId;
                        layer.open({
                                       title: false,
                                       type: 2,
                                       content: url,
                                       area: ['500px', '230px'],
                                       end: function () {
                                           document.getElementById("chargebackBtn").parentNode
                                               .firstChild.click();
                                       }
                                   });
                    }
                },
                    {
                        id: "SupplementaryBtn",
                        value: "补充资料",
                        click: function () {
                            var ids = $('#declarationsDataGrid')
                                .jqGrid('getGridParam', 'selarrrow');
                            if (ids.length != 1) {
                                jw.alert("一次只能处理一份报关单");
                                return;
                            }
                            var rowData = $("#declarationsDataGrid").jqGrid('getRowData', ids[0]);
                            var declaId = rowData.id;
                            layer.open({
                                           type: 2,
                                           offset: ['5%', '12%'],
                                           content: '/business/uploadMain?type=secondSup#'
                                                    + declaId,
                                           area: ['815px', '620px']
                                       });
                        }
                    }
                    <c:if test="${isSignWS eq true}">
                    , {
                        id: "confirmSanLianDanBtn",
                        value: "确认三联单",
                        click: function () {
                            var ids = $('#declarationsDataGrid')
                                .jqGrid('getGridParam', 'selarrrow');
                            if (!ids) {
                                jw.alert("请选择需要确认的报关单");
                                return;
                            }
                            var dids = "";
                            for (var i = 0; i < ids.length; i++) {
                                dids += "," + ids[i];
                            }
                            dids = dids.substr(1, dids.length);
                            $.ajax({
                                       type: "post",
                                       cache: false,
                                       url: '/business/confirmSanLianDan',
                                       data: {"ids": dids},
                                       dataType: "json",
                                       success: function (result) {
                                           layer.msg(result.msg);
                                           $("#declarationsDataTable").mrdForm("refreshGrid");
                                       }
                                   });
                        }
                    }
                    </c:if>
                ]

            },
            grid: {
                id: "declarationsDataGrid",
                title: "查询结果",
                url: "findValidList",
                multiselect: true,
                colModel: [{
                    index: "ID",
                    name: "id",
                    hidden: true
                }, {
                    label: "操作",
                    sortable: false,
                    width: 120,
                    buttons: [{
                        key: "id1",
                        value: "详情",
                        click: function (gridid, rowId, rowdata) {
                            doEditSingle(rowId, rowdata.declaration_type, false, 'toValid');
                        }
                    }, {
                        key: "id2",
                        value: "流程记录",
                        hide: true,
                        click: function (gridid, rowId, rowdata) {

                        }
                        /* }, {
                         key: "id3",
                         value: "单一窗口测试",
                         click: function (gridid, rowId, rowdata) {
                         buildxml(rowId);
                         }*/
                    }, {
                        key: "id4",
                        value: "查验货物",
                        hide: function (rowdata) {
//                            return (rowdata.state === "DS05" || rowdata.state === "DS10"
//                                    || rowdata.state === "DS11");
                        },
                        click: function (gridid, rowId, rowdata) {
                            doSelect(rowId);
                        }
                    }],
                    formatter: $.jqGrid.custom.formatter.button
                }, {
                    index: "BUSINESS_ID",
                    name: "businessId",
                    label: "业务编号",
                    width: 120,
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a href=\"javascript:;\" onclick=\"javascript:doEditSingle('"
                               + rowObject.id + "','"
                               + rowObject.declaration_type + "',false,'toValid');\">" + cellvalue
                               + "</a>";
                    }
                }, {
                    name: "businessId",
                    hidden: true
                }, {
                    index: "WORK_NO",
                    name: "workNo",
                    label: "三联单编号",
                    hidden: !${isFG}
                }, {
                    index: "SNO",
                    name: "sno",
                    label: "报关单号",
                    width: 100,
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a title='点击此处绑定/修改报关单号' href=\"javascript:;\" onclick=\"javascript:doEditSNO('"
                               + rowObject.id + "','"
                               + cellvalue + "');\">" + (cellvalue ? cellvalue : "绑定报关单号") + "</a>";
                    }
                }, {
                    index: "DATA_TYPE",
                    name: "dataType",
                    width: 80,
                    label: "直/转类型",
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a title='点击此处直航转关互转' href=\"javascript:;\" onclick=\"javascript:doZhuanGuan('"
                               + rowObject.id + "','"
                               + cellvalue + "');\">" + (cellvalue ? cellvalue : "直航") + "</a>";
                    }
                }, {
                    sortable: false,
                    label: "船名/船代",
                    width: 100,
                    formatter: function (cellvalue, options, rowObject) {
                        return (rowObject.shipName ? rowObject.shipName : "") + " / "
                               + (rowObject.shipCode ? rowObject.shipCode : "") + " / "
                               + (rowObject.transportNa ? rowObject.transportNa : "");
                    }
                }, {
                    index: "CONTAINER_NO",
                    name: "containerNo",
                    label: "集装箱号",
                    width: 110
                }, {
                    index: "BL_NO",
                    name: "blNo",
                    width: 100,
                    label: "提运单号"
                }, {
                    index: "COMPANY_NAME",
                    name: "companyName",
                    width: 180,
                    label: "收发货人"
                }, {
                    index: "STATE",
                    name: "state",
                    width: 80,
                    label: "业务状态",
                    formatter: function (cellvalue, options, rowObject) {
                        var sname = "";
                        switch (cellvalue) {
                            case "DS00":
                                sname = "草稿状态";
                                break;
                            case "DS01":
                                sname = "待审核";
                                break;
                            case "DS02":
                                sname = "已审核";
                                break;
                            case "DS03":
                                sname = "驳回";
                                break;
                            case "DS04":
                                sname = "已安排";
                                break;
                            case "DS05":
                                sname = "放行";
                                break;
                            case "DS06":
                                sname = "初审";
                                break;
                            case "DS07":
                                sname = "复审";
                                break;
                            case "DS08":
                                sname = "现场递单";
                                break;
                            case "DS09":
                                sname = "查验";
                                break;
                            case "DS10":
                                sname = "海关放行";
                                break;
                            case "DS11":
                                sname = "商检放行";
                                break;
                            case "DS13":
                                sname = "海关退单";
                                break;
                            case "DS031":
                                return "申请驳回";
                            case "DS120":
                                return "查验中";
                            case "DS121":
                                return "查验完成";
                            case "DS122":
                                return "查验不通过";
                            case "DS124":
                                return "海关放行";
                            case "DS125":
                                return "商检放行";
                            case "DS126":
                                return "其他放行";
                            default:
                                sname = cellvalue;
                        }
                        return sname;
                    }
                }, {
                    index: "QPDRSJ",
                    name: "qpdrsj",
                    label: "QP同步时间",
                    width: 100,
                    formatter: 'date',
                    formatoptions: {
                        srcformat: 'Y-m-d H:i:s',
                        newformat: 'm-d H:i'
                    }
                }, {
                    sortable: false,
                    label: "强制同步操作",
                    width: 90,
                    formatter: function (cellvalue, options, rowObject) {
//                                    if(rowObject.qpscsj)
                        return "<a title='点击此处强制同步数据到小工具' href=\"javascript:;\" onclick=\"javascript:fsyncQPData('"
                               + rowObject.id + "','" + rowObject.businessId + "');\">强制同步</a>";
//                                    else return "";
                    }
                }, {
                    index: "DECLARATION_TYPE",
                    name: "declarationType",
                    label: "进出口类型",
                    width: 80,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue && cellvalue == "E") {
                            return "出口";
                        } else if (cellvalue && cellvalue == "I") {
                            return "进口";
                        }
                    }
                }, {
                    label: "底单上传",
                    sortable: false,
                    width: 65,
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a title='点击此处上传/修改上传底单' href=\"javascript:;\" onclick=\"javascript:jw.dialog({iframe : 'uploadMain?type=didan#"
                               + rowObject.id
                               + "',title : '上传底单',iframeFetchTitle : false,width : 600,height : 400});\">上传底单</a>";
                    }
                }, {
                    index: "CONTRACT_NO",
                    name: "contractNo",
                    width: 100,
                    label: "合同协议号"
                }, {
                    index: "customer.COM_NAME",
                    name: "customerCompany.comName",
                    width: 160,
                    label: "实际托运人"
                }, {
                    index: "CONFIRM_TIME",
                    name: "confirmTime",
                    width: 125,
                    label: "业务提交时间"
                }, {
                    index: "VALIDATE_TIME",
                    name: "validateTime",
                    width: 125,
                    label: "审核时间"
                }, {
                    name: "creator",
                    label: "下单人",
                    formatter: function (cellvalue, options, rowObject) {
                        return "<a href=\"javascript:;\" onclick=\"javascript:showContactWay('"
                               + rowObject.id + "','creator');\">" + cellvalue + "</a>";
                    }
                }, {
                    index: "validator.U_NAME",
                    name: "validator.uName",
                    width: 60,
                    label: "核实人",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue) {
                            return "<a href=\"javascript:;\" onclick=\"javascript:showContactWay('"
                                   + rowObject.id + "','validator');\">" + cellvalue + "</a>";
                        } else {
                            return "";
                        }
                    }
                }, {
                    index: "QPSCSJ",
                    name: "qpscsj",
                    label: "QP上传时间",
                    width: 125,
                    formatter: 'date',
                    formatoptions: {
                        srcformat: 'Y-m-d H:i:s',
                        newformat: 'm-d H:i'
                    }
                }, {
                    index: "QP_DJZT",
                    name: "qpDjzt",
                    width: 90,
                    label: "海关通关状态",
                    hidden: true
                }, {
                    index: "QP_TYNO",
                    name: "qpTyno",
                    width: 100,
                    label: "海关统一编号",
                    hidden: true
                }, {
                    name: "applied",
                    hidden: true
                }, {
                    index: "CONFIRM_TYPE",
                    name: "confirmType",
                    label: "确认三联单",
                    formatter: function (cellvalue) {
                        if (cellvalue == '1') {
                            return "已确认";
                        } else {
                            return "未确认";
                        }
                    }
                }],
                sortname: "BUSINESS_ID",
                sortorder: "desc",
                ondblClickRow: function (rowid, iRow, iCol, e) {
                    if (rowid) {
                        var rowData = $("#declarationsDataGrid").jqGrid("getRowData", rowid);
                        doEditSingle(rowid, rowData.declaration_type, false, 'toValid');
                    }
                },
                gridComplete: function () {
                    $("#declarationsDataGrid").jqGrid("setGridWidth", 2300);
                    markCustomerReject();
                }
            }
        };

        /**
         * 给是白名单的界面表格中加入两列：海关状态 、 上传电子口岸
         */
        var wayCodes = '${declarationWayCodes}';
        if (wayCodes) {
            //将海关状态一列插入到配置中，定位在11列
            formSetting.grid.colModel.splice(11, 0, {
                index: "DECLA_STATUS",
                name: "declaStatus",
                width: 80,
                label: "电子口岸状态",
                formatter:function (cellvalue, options, rowObject) {
                    if(cellvalue == "暂存失败"){
                        return "<a href=\"javascript:;\" onclick=\"javascript:showFailInfo('"
                               + rowObject.failInfo + "');\">" + cellvalue + "</a>";
                    }
                    return cellvalue;
                }
            });
            //将上传电子口岸一列插入到配置中，定位在14列，要算上新增的“电子口岸状态”
            formSetting.grid.colModel.splice(14, 0, {
                sortable: false,
                name: 'uploaddzka',
                label: "上传电子口岸",
                width: 100,
                formatter: function (cellvalue, options, rowObject) {
                    var text = "上传至电子口岸";
                    var declaStatus = rowObject.declaStatus;
                    var showOpaLink = false; //作为是否显示操作链接的判断依据
                    if (declaStatus === undefined || declaStatus === null || declaStatus === "") {
                        showOpaLink = true;
                    } else if (declaStatus.indexOf("失败") !== -1) {
                        text = "重新上传";
                        showOpaLink = true;
                    } else if (declaStatus.indexOf("暂存") !== -1) {
                        text = "重新上传";
                        showOpaLink = true;
                    }
                    if (showOpaLink) {
                        return "<a href=\"javascript:;\" onclick=\"javascript:up2cargoDecla('"
                               + rowObject.id + "');\">" + text + "</a>";
                    } else {
                        return "";
                    }
                }
            });
            formSetting.grid.colModel.splice(15,0,{
                name:"failInfo",
                hidden:true
            });
        }
        $(document).ready(function () {
            $("#declarationsDataTable").mrdForm(formSetting);
            var zg = form_in_control_5;
            if (zg) {
                zg.onclick = function () {
                    if (zg.value == "转关") {
                        zg.value = "直航";
                    } else {
                        zg.value = "转关";
                    }
                }
            }
        });

        /**
         * 强制同步QP数据
         */
        var fsyncQPData = function (datas, sdatas) {
            $.ajax({
                       type: "post",
                       cache: false,
                       url: '/datalock/lock.do?opaId=VDBS&bidId=' + datas,
                       dataType: "json",
                       success: function (data) {
                           if ("200" == data.errcode) {
                               syncQPData(datas, sdatas, false, '1');
                           } else {
                               jw.alert(data.errmsg);
                           }
                       }
                   });
        }

        /**
         * 同步QP数据
         * @param datas
         * @param sdatas
         * @param auto
         * @param fu
         */
        function syncQPData(datas, sdatas, auto, fu) {
            var fdatas = [];
            if (typeof datas == 'string') {
                fdatas.push(datas);
            } else {
                fdatas = datas;
            }
            var fsdatas = [];
            if (typeof sdatas == 'string') {
                fsdatas.push(sdatas);
            } else if (typeof sdatas == 'undefined') {
                fsdatas = fdatas;
            } else {
                fsdatas = sdatas;
            }
            var loading = function (datas, sdatas, posi) {
                console.log("loading#" + posi);
                var sposi = posi + 1;
                var set = false;
                $(".bd").each(function (i, dom) {
                    if ($(dom).text().indexOf("同步中") != -1) {
                        set = true;
                        $(dom).append("<br/>业务编号：" + sdatas[posi] + "同步中，");
                        dom.parentElement.parentElement.parentElement.style.height =
                            dom.parentElement.parentElement.parentElement.style.height.replace(
                                /px/, '') - 0 + 21 + 'px';
                    }
                });
                if (!set) {
                    jw.alert("业务编号：" + sdatas[posi] + "同步中，");
                    $(".bd")[0].parentElement.parentElement.parentElement.style.width = '450px';
                    $(".bd")[0].style.width = '400px';
                }
            }
            var complete = function (datas, sdatas, posi, result, timeUsed) {
                console.log("complete#" + posi);
                var rmsg = result.msg;
                var sposi = posi + 1;
                var set = false;
                $(".bd").each(function (i, dom) {
                    if ($(dom).text().indexOf("同步中") != -1) {
                        set = true;
                        $(dom).append(rmsg + "。");
                    }
                });
                if (!set) {
                    jw.alert("业务编号：" + sdatas[posi] + "同步中，" + rmsg + "。");
                }
                var nposi = posi + 1;
                if (nposi < datas.length) {
                    doOne(datas, sdatas, nposi);
                }
                else {
                    $(".bd").each(function (i, dom) {
                        if ($(dom).text().indexOf("同步中") != -1) {
                            $(dom).append("<br/>全部同步完成。");
                        }
                    });
                }
            }
            var doOne = function (datas, sdatas, posi) {

                if (posi < datas.length) {
                    loading(datas, sdatas, posi);
                    var ld = new Date();
                    $.ajax({
                               type: "post",
                               cache: false,
                               url: "declaration-syncQPData.do?did=" + datas[posi] + (fu
                                                                                      == undefined
                                   ? "" : ("&fu=" + fu)),
                               dataType: "json",
                               success: function (result) {
                                   console.log(result);
                                   var timeUsed = new Date().getTime() - ld.getTime();
                                   console.log("timeUsed=" + timeUsed);
                                   complete(datas, sdatas, posi, result, timeUsed);
                               }
                           });
                }
            }
            if (auto || confirm('确认开始同步选中的[' + fdatas.length + ']条数据？')) {
                doOne(fdatas, fsdatas, 0)
            }
        }

        /**
         * 将报关单上传到单一窗口
         * @param declarationId
         */
        function up2cargoDecla(declarationId) {
            var ajaxFun = function (wayCode) {
                $.ajax({
                           url: "up2cargoDecla",
                           method: 'post',
                           data: {declarationId: declarationId, wayCode: wayCode},
                           dataType: 'json',
                           success: function (result) {
                               layer.alert(result.msg);
                               $("#declarationsDataGrid").gridMethods().reload();
                           }
                       });
            };
            var wayCodeArr = wayCodes.split(",");
            if (wayCodeArr === 0) {
                layer.msg("入口已被关闭");
            }
            if (wayCodeArr.length === 1) {
                layer.confirm("请确认是否上传", function () {
                    ajaxFun(wayCodeArr[0]);
                });
                return;
            }
            var wayCodeTitle = {
                "GZ_PORT_HTTPS": "广州版",
                "COM_PORT_FTP": "国家版"
            };
            var btnArr = [];
            var confirmString = "layer.open({id :'CN_PORT_TIP',content:'请您选择入口',btn: btnArr, btnAlign:'c',";
            for (var i = 0; i < wayCodeArr.length; i++) {
                var wc = wayCodeArr[i];
                btnArr.push(wayCodeTitle[wc]);
                confirmString += "btn" + (i + 1) + ":function(){ajaxFun('" + wc + "');}, "
            }
            confirmString = confirmString.substring(0, confirmString.length - 2);
            confirmString += "})";
            eval(confirmString);
        }

        /**
         * 标记出客户正申请驳回的报关单
         */
        function markCustomerReject() {
            var ids = $("#declarationsDataGrid").jqGrid("getDataIDs");
            var rowDatas = $("#declarationsDataGrid").jqGrid("getRowData");
            var declarationIds = '';
            for (var i = 0; i < rowDatas.length; i++) {
                var rowData = rowDatas[i];
                declarationIds += rowData.id + ",";
            }
            $.ajax({
                       url: "/business/reject/rejectRecord",
                       cache: false,
                       dataType: 'json',
                       data: {"declarationIds": declarationIds},
                       success: function (data) {
                           rejectRecords = data.data;
                           if (rejectRecords) {
                               for (var i = 0; i < rowDatas.length; i++) {
                                   var rejectRecord = rejectRecords[i];
                                   if (rejectRecord) {
                                       if (rejectRecord.acceptedResult == 'INITIATED') {
                                           $("#" + ids[i] + " td").css("background-color", "pink");
                                           $("#declarationsDataGrid")
                                               .jqGrid('setCell', ids[i], 'applied', true);
                                           $("#declarationsDataGrid")
                                               .jqGrid('setCell', ids[i], 'state',
                                                   rowDatas[i].state + '</br>' +
                                                   "<a href=\"javascript:;\" onclick=\"javascript:showRecord('"
                                                   + i + "');\">申请驳回</a>");
                                       } else if (rejectRecord.acceptedResult == 'NOT_ACCEPTED') {
                                           $("#declarationsDataGrid")
                                               .jqGrid('setCell', ids[i], 'state',
                                                   rowDatas[i].state + '</br>' +
                                                   "<a href=\"javascript:;\" onclick=\"javascript:showRecord('"
                                                   + i + "');\">不同意驳回</a>");
                                       } else if (rejectRecord.acceptedResult == 'CHARGEBACK') {
                                           $("#declarationsDataGrid")
                                               .jqGrid('setCell', ids[i], 'state',
                                                   "<a href=\"javascript:;\" onclick=\"javascript:showRecord('"
                                                   + i + "');\">" + rowDatas[i].state + "</a>");
                                       }
                                   }
                               }
                           }
                       }

                   });
        }

        function showRecord(index) {
            if (rejectRecords) {
                if (rejectRecords[index].acceptedResult == 'INITIATED') {
                    layer.alert("驳回原因：" + rejectRecords[index].rejectReason);
                } else if (rejectRecords[index].acceptedResult == 'NOT_ACCEPTED') {
                    layer.alert("不同意原因：" + rejectRecords[index].notAcceptReason +
                                (rejectRecords[index].acceptedOpinion ? '</br>'
                                + "受理意见：" + rejectRecords[index].acceptedOpinion : ""));
                } else if (rejectRecords[index].acceptedResult == 'CHARGEBACK') {
                    layer.alert("退单原因：" + rejectRecords[index].rejectReason);
                }
            }
        }

        /**
         * 显示失败原因
         */
        function showFailInfo(failInfo) {
            if(failInfo){
                layer.alert(failInfo);
            }
        }
    </script>
    <style type="text/css">
        .layui-layer-btn .layui-layer-btn1,
        .layui-layer-btn .layui-layer-btn2,
        .layui-layer-btn .layui-layer-btn3,
        .layui-layer-btn .layui-layer-btn4 {
            border-color: #4898d5;
            background-color: #2e8ded;
            color: #fff;
        }
    </style>
</head>
<body>
<div id="declarationsDataTable"></div>
<script type="application/javascript">
    function doSelect(declarationId) {
        $.ajax({
                   type: "post",
                   cache: false,
                   url: '../datalock/lock?opaId=VDBS&bidId=' + declarationId,
                   dataType: "json",
                   success: function (data) {
                       if ("200" == data.errcode) {
                           window.location.href =
                               '/views/yxtPc/pages/record.html?bussId=' + declarationId;
                       }
                       else {
                           jw.alert(data.errmsg);
                       }
                   }
               });
        /* ajaxLoader.ajaxPost('../datalock/lock?opaId=VDBS&bidId='+id, {}, function(data){
         if ("200" == data.errcode) {
         window.location.href = '/views/yxtPc/pages/record.html?bussId=' + declarationId;
         }
         else {
         jw.alert(data.errmsg);
         }
         });*/
    }

    function doZhuanGuan(declarationId) {
        ajaxGet('../datalock/lock?opaId=VDBS&bidId=' + declarationId, function (data) {
            if ("200" == data.errcode) {
                jw.dialog({
                              iframe: "/business/declaration-toZhuanGuan#"
                                      + declarationId + "&${isSignWS}",
                              title: "直航转关互转",
                              iframeFetchTitle: false,
                              width: 500,
                              height: 150
                          });
            } else {
                jw.alert(data.errmsg);
            }
        });

    }

    function buildxml(declarationId) {
        $.ajax({
                   url: "buildxml",
                   method: 'post',
                   data: {did: declarationId},
                   dataType: 'json',
                   success: function (result) {
                       jw.alert(result.msg);
                   }
               });
    }
</script>
</body>
</html>
